import typescript from "rollup-plugin-typescript2";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";

const mode = process.env.MODE;
const isProd = mode === "prod";
const pkg = require("./package.json");

export default {
  input: `lib/index.ts`,
  external: ["axios"],
  output: [
    {
      file: pkg.module,
      format: "es",
      sourcemap: !isProd,
    },
    {
      file: "build/index.cjs.js",
      format: "cjs",
      sourcemap: !isProd,
    },
    {
      file: "build/index.global.js",
      name: "Lazy",
      format: "iife",
      sourcemap: !isProd,
      globals: {
        axios: "axios",
      },
    },
  ],
  plugins: [
    nodeResolve(),
    commonjs(),
    typescript({
      useTsconfigDeclarationDir: true,
      tsconfigOverride: { compilerOptions: { sourceMap: !isProd } },
    }),
  ],
};
